{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#画图\n",
    "import cv2\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "image=cv2.imread('./data/trains_resize/cat.1.jpg')\n",
    "img = np.array(cv2.resize(image,(208,208))).astype(np.float32)\n",
    "cv2.imwrite('./data/trains_resize/cat.1.jpg',img)\n",
    "plt.imshow(img)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#resize图片，如数据不合法则直接删除\n",
    "import cv2\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "#path=\"/home/wjj/My-TensorFlow-tutorials-master/cats_dogs/data/trains_resize/\"\n",
    "jpg_list=os.listdir(path)\n",
    "for jpg in jpg_list:\n",
    "    jpg_path = path + jpg\n",
    "    image=cv2.imread(jpg_path)\n",
    "    print(\"*********************\")\n",
    "    print(jpg_path)\n",
    "    try:\n",
    "        img = np.array(cv2.resize(image,(208,208))).astype(np.float32)\n",
    "        cv2.imwrite(jpg_path,img)\n",
    "    except:\n",
    "        print(jpg_path,\"jpg was broken!!!\")\n",
    "        os.system(\"rm %s\" % jpg_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#convert格式png2jpg\n",
    "import cv2\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "path=\"/samba/HDD/dataset_dzkd_radar/trains/\"\n",
    "jpg_list=os.listdir(path)\n",
    "for png in jpg_list:\n",
    "    png_path = path + jpg\n",
    "    image=cv2.imread(png_path)\n",
    "    print(\"*********************\")\n",
    "    print(png_path)\n",
    "    jpg_path=png_path[:-3]+\"jpg\"\n",
    "    print(jpg_path)\n",
    "#     plt.imshow(img)\n",
    "#     plt.show()\n",
    "    try:\n",
    "        cv2.imwrite(jpg_path,image)\n",
    "    except:\n",
    "        print(jpg_path,\"jpg was broken!!!\")\n",
    "        #os.system(\"rm %s\" % jpg_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#rename\n",
    "import os\n",
    "path=\"/samba/HDD/dataset_dzkd_radar/test/\"\n",
    "jpg_list=os.listdir(path)\n",
    "index = 1\n",
    "for jpg in jpg_list:\n",
    "    jpg_path = path + jpg\n",
    "    newname =jpg_path[:-3]+\"png\"\n",
    "    os.rename(jpg_path,newname)\n",
    "    print(\"*********************\")\n",
    "    print(jpg_path)\n",
    "    print(newname)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
